//
//  MyOutlineView.m
//  HiQ
//
//  Created by maxwell pang on 12-8-6.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MyOutlineView.h"

@implementation MyOutlineView

-(void)awakeFromNib
{
	[[self enclosingScrollView] setDrawsBackground: NO];
}

-(void)drawBackgroundImage
{
	if (_backgroundImage != nil)
	{
		NSRect visRect = [[self enclosingScrollView] documentVisibleRect];

		[_backgroundImage setFlipped:YES];
		[_backgroundImage drawInRect:NSMakeRect(visRect.origin.x, visRect.origin.y, [self frame].size.width, [self frame].size.height)
						fromRect:NSMakeRect(0,0,[_backgroundImage size].width, [_backgroundImage size].height)
						operation:NSCompositeCopy
						fraction:1.0];
		[_backgroundImage setFlipped:NO];
	}
}

- (void)drawBackgroundInClipRect:(NSRect)clipRect
{	
	[super drawBackgroundInClipRect:clipRect];
        
	[self drawBackgroundImage];
}

- (void)drawRect:(NSRect)drawRect
{
	[self drawBackgroundImage];
	[super drawRect: drawRect];
}

- (void)setBackgroundImage:(NSImage*)image
{
	_backgroundImage = image;
	
	[self setNeedsDisplay: YES];
}

- (void)clearBackgroundImage
{
	if (_backgroundImage != nil)
	{
		_backgroundImage = nil;
	}
	
	[self setNeedsDisplay: YES];
}

// method used to expand a particular item showing its children
- (void)expandItem:(id)item expandChildren:(BOOL)expandChildren
{
	[super expandItem:item expandChildren: expandChildren];
	[self setNeedsDisplay: YES];	// make sure the background image is redrawn (rescaled to fit the outline area)
}

// method used to collapse a particular item, hiding its children
- (void)collapseItem:(id)item collapseChildren:(BOOL)collapseChildren
{
	[super collapseItem:item collapseChildren: collapseChildren];
	[self setNeedsDisplay: YES];	// make sure the background image is redrawn (rescaled to fit the outline area)
}

@end





